// pages/shop/shop.js
var app = getApp();
var that;
Page({
  data: {
    success: 0,  //支付成功后返回首页
    ordersn: '',  //支付成功的订单号
   
   
    shuaxin: true,
    keyword: '',
    no_pro: false,  //是否搜索到商品
    open: "",  //点击过快设置的openid
    i: 0,
    search_ss: "block",
    search_input: "none",
    search_animationData: {},
    recommend_shop: '', //推荐的商品
    shopIndex: [],
    objectShop: []
  },
  onLoad: function (options) {
    that = this;
    that.get_shop_msg(); //获取店铺信息
    app.getUserInfo(function (res) {
      that.setData({ open: res.openid });
    }, function () {
      that.onLoad(options)
    });
    
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          h: res.windowHeight
        });
      }
    });

    this.setData({
      index: wx.getStorageSync('shop_index')
    });

  },
  onShow: function () {
    app.check_vs(); //检查版本
  

  },



  select_shop: function () {
    //if (that.data.search_ss=="block"){
    //that.search_start();
    //}else{
    //if (that.data.keyword != "") {
    wx.navigateTo({
      //url: './shop_search?keyword=' + that.data.keyword
      url: './shop_search'
    })

  },
  bindPickerChange: function (e) {
    that = this;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var shop_id = that.data.shopIndex[e.detail.value].id;
    wx.setStorageSync('shop_id', shop_id);
    this.setData({
      index: e.detail.value
    });
    wx.setStorageSync('shop_index', e.detail.value);

    wx.reLaunch({
      url: 'shop'
    })
  },

  get_shop_msg: function () {

    app.req("get_shop.html", {}, function (res) {
      var shop_arr = [];
      if (res.status == "success") {
        for (var shop in res.mess) {
          shop_arr.push(res.mess[shop]);

        }

        that.setData({ shopIndex: shop_arr });
        that.setData({ objectShop: res.mess });
      } else if (res.status == "error") {
        app.toast_up(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.get_service_msg()
          }
        })
      }
    })
  },



  back_f: function () { that.setData({ success: 0 }) },//点击返回首页时隐藏

  


})